package com.metaverse.backend.dto;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Builder;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.AttributeConverter;

@AllArgsConstructor
@Builder
public class Minter {
    private Long   id;
    private String name;
    private String avatar;
    private String account;

    public class MinterConverter implements AttributeConverter<Minter, String> {

        @Override
        public String convertToDatabaseColumn(Minter minter) {
            if (minter == null) return null;
            return JSON.toJSONString(minter);
        }

        @Override
        public Minter convertToEntityAttribute(String s) {
            if (StringUtils.isEmpty(s)) {
                return null;
            }
            return JSON.parseObject(s, Minter.class);
        }
    }
}
